package com.servlet;

import com.entity.House;
import com.opensymphony.xwork2.ActionSupport;
import com.service.BaseService;
import com.service.impl.BaseServiceImpl;
import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
import org.junit.Test;

import java.util.List;


public class HouseList extends ActionSupport {
    static BaseService baseService = new BaseServiceImpl();
    private List<House> houseList;
    private String result;

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public List<House> getHouseList() {
        return houseList;
    }

    public void setHouseList(List<House> houseList) {
        this.houseList = houseList;
    }

    @Override
    public String execute() throws Exception {
        houseList = baseService.getAllHouse();
        JsonConfig jsonConfig=new JsonConfig();
        jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
        JSONArray jsonArray= JSONArray.fromObject(houseList,jsonConfig);
        System.out.println(jsonArray);
        return SUCCESS;
    }
    @Test
    public void test(){
        String t;
        try {
            t=execute();
            System.out.println(t);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
